//
//  WPCHomepageViewCell.m
//  Wallpaper.co
//
//  Created by zhou_yuepeng on 2017/9/1.
//  Copyright © 2017年 www.dahuatech.com. All rights reserved.
//

#import "WPCHomepageViewCell.h"
#import "UIImageView+WebCache.h"

@interface WPCHomepageViewCell()
@property (nonatomic, strong) UIImageView *imgView;
@end

@implementation WPCHomepageViewCell

+ (NSString*)cellIdentifier
{
    return NSStringFromClass([self class]);
}

- (instancetype)initWithFrame:(CGRect)frame
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        /* 禁用图片解压缩功能(会大量消耗内存) */
        [[SDImageCache sharedImageCache] setShouldDecompressImages:NO];
        [[SDWebImageDownloader sharedDownloader] setShouldDecompressImages:NO];
        
        /* 限制内存缓存最大值 */
        [[SDImageCache sharedImageCache] setMaxMemoryCost:1024*1024*5];
    });
    
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.5];
        
        _imgView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self.contentView addSubview:_imgView];
    }
         
    return self;
}

- (void)loadImageWithURL:(NSURL*)URL
{
    /* 只有图片缩略图加载完成才允许点击预览 */
    self.userInteractionEnabled = NO;
    [_imgView sd_setImageWithURL:URL completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        self.userInteractionEnabled = YES;
    }];
}

@end
